Skip to content

Conversation

@Shvandre
Copy link
Collaborator

@Shvandre Shvandre commented Oct 8, 2025

Closes #175

@github-actions
Copy link

github-actions bot commented Oct 8, 2025

To fix the formatting issues:

  1. Install necessary dependencies: npm ci
  2. Then, run this command:
npx remark -o --silent --silently-ignore guidebook/debug.mdx techniques/gas.mdx 

Copy link
Collaborator

@skywardboundd skywardboundd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice PR, can we add link to gas-utility file?

@Shvandre Shvandre marked this pull request as ready for review October 8, 2025 12:34
@github-actions
Copy link

github-actions bot commented Oct 8, 2025

Thanks for the update to the techniques docs. One high‑severity fix is needed before merge.

Findings (1)

High (1)

[HIGH] Missing frontmatter; page title rendered as body text

Location: https://github.com/tact-lang/mintlify-ton-docs/blob/b025787e285117b90fde9b9afa584fad875b4228/techniques/gas.mdx?plain=1#L1-L1

Description:
The YAML frontmatter was removed and replaced by an in‑body H2 ## title: "Estimate gas usage in TON contracts". The site expects page metadata (including the title) in frontmatter, with no visible in‑body H1; rendering the title: key as body text breaks metadata, disrupts heading hierarchy/TOC, and conflicts with the site’s title handling (see https://github.com/tact-lang/mintlify-ton-docs/blob/main/contribute/style-guide-extended.mdx?plain=1#L282-L284).

Suggestion:
Restore YAML frontmatter and remove the in‑body “title” heading.

-## title: "Estimate gas usage in TON contracts"
+---
+title: "Estimate gas usage in TON contracts"
+---

@github-actions
Copy link

github-actions bot commented Oct 9, 2025

To fix the formatting issues:

  1. Install necessary dependencies: npm ci
  2. Then, run this command:
npx remark -o --silent --silently-ignore guidebook/debug.mdx techniques/gas.mdx 

@github-actions
Copy link

github-actions bot commented Oct 9, 2025

To fix the formatting issues:

  1. Install necessary dependencies: npm ci
  2. Then, run this command:
npx remark -o --silent --silently-ignore guidebook/debug.mdx standard/tokens/airdrop.mdx techniques/gas.mdx 

@github-actions
Copy link

github-actions bot commented Oct 9, 2025

To fix the formatting issues:

  1. Install necessary dependencies: npm ci
  2. Then, run this command:
npx remark -o --silent --silently-ignore guidebook/debug.mdx standard/tokens/airdrop.mdx techniques/gas.mdx 

Copy link
Collaborator

@skywardboundd skywardboundd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice pr!
Can we add may be more pics
I have several suggestions:

@Shvandre
Copy link
Collaborator Author

@skywardboundd sure, examples in ts will be added as part of #620

@github-actions
Copy link

To fix the formatting issues:

  1. Install necessary dependencies: npm ci
  2. Then, run this command:
npx remark -o --silent --silently-ignore guidebook/debug.mdx techniques/gas.mdx 

Copy link
Collaborator

@anton-trunov anton-trunov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's fix the issues by @skywardboundd and the AI review issues too

@anton-trunov anton-trunov changed the title feat: Gas calculation pattern feat: gas calculation pattern Oct 22, 2025
@anton-trunov anton-trunov marked this pull request as draft October 22, 2025 21:23
@Shvandre
Copy link
Collaborator Author

/review

@Shvandre Shvandre marked this pull request as ready for review October 28, 2025 08:59
@Shvandre Shvandre marked this pull request as draft October 28, 2025 08:59
@Shvandre Shvandre marked this pull request as ready for review October 28, 2025 09:32
@Shvandre Shvandre marked this pull request as draft October 28, 2025 09:32
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR—I've left several suggestions in techniques/gas.mdx: please apply the inline suggestions.

Shvandre and others added 2 commits October 28, 2025 13:38
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@Shvandre Shvandre marked this pull request as ready for review October 28, 2025 10:54
@skywardboundd skywardboundd self-requested a review October 28, 2025 12:21
skywardboundd
skywardboundd previously approved these changes Oct 28, 2025
Copy link
Collaborator

@skywardboundd skywardboundd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me!

Kaladin13
Kaladin13 previously approved these changes Oct 28, 2025
@Shvandre
Copy link
Collaborator Author

Also there is a task on rewriting examples on Tolk. I am not sure that it will make the article better, so this issue will be closed in another PR. #1003

@Shvandre Shvandre dismissed stale reviews from Kaladin13 and skywardboundd via 71588c0 October 28, 2025 14:05
@verytactical
Copy link
Collaborator

/review

@novusnota
Copy link
Collaborator

novusnota commented Oct 29, 2025

Re-deployed: View deployment

I'm not sure if Mintlify's bot will pick up new updates here, because previously deployments were skipped for this branch and all other branches that were moved from the previous org/repo place.

@verytactical verytactical marked this pull request as draft October 29, 2025 16:32
A,B,80
A,Storage fee (A),5
A,Compute fee (A),15
A,Forward fee (A->B),20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the A's remaining balance?

This article covers abstract contracts system, not connected to any existing project. However, it's primary applicable to contract systems that uses [carry-value pattern.](/contract-dev/carry-value)
</Aside>

It is crucial to understand that there is no separate message balance and contract balance. After the message is received, coins are added to the contract balance, and then the contract is executed. Sending message mods and reserve actions help to properly divide contract balance in the action phase. This diagram of a possible value flow illustrates this. Note, that this diagram is not connected to the diagram above, it illustrates different fact.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the message is received, coins are added to the contract balance, and then the contract is executed.

This is not absolutly true. It depends on an order of the storage and credit phases.


The reason for this requirement is that reverting the contract system state is usually not possible, because the toncoins are already spent.

In case you are writing a contract system, where correctness depends on successful execution of the rest of the transaction trace, then you need to guarantee that there are enough attached toncoins in an incoming message to cover all fees. This article describes how to compute those fees.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are writting

We don't talk to a reader. This is a documentation, it describes facts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many such cases in the article, please handle them all.


ComputeDataSize have the second argument - maximum number of cells to visit. If it is ok to set in in _8192_ since it is the [limit for message size](/foundations/limits#message-and-transaction-limits).

```tact
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to check that the calculation really works as expected. We discussed it personally.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it should be:

let sizeBody = computeDataSize(msg.body.toCell(), 8192);
let sizeStateInit = computeDataSize(msg.init.toCell(), 8192);

let fwdFee = getForwardFee(sizeBody.cells + sizeStateInit.cells - 2, sizeBody.bits + sizeStateInit.bits - msg.body.toCell().bits() - msg.init.toCell().bits(), isAccountInMasterchain);

If this is still not true, then you need to clarify exactly how the function getForwardFee() works.

Copy link
Contributor

@Karkarmath Karkarmath Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, it must be

let sizeMsg = computeDataSize(msg.toCell(), 8192);

let fwdFee = getForwardFee(sizeMsg.cells - 1, sizeMsg.bits - msg.toCell().bits(), isAccountInMasterchain);

fwdFee = basePrice + priceForCells * cells + priceForBits * bits
```

So, when one want to send message, with `a + b` cells and `x + y` bits, the forward fee won't be `getForwardFee(a + b, x + y)`, but rather `basePrice + priceForCells * (a + b) + priceForBits * (x + y)`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, when one want to send message

Perhaps, two messages?


**Approach 2: Cover storage on demand**

In the worst case the storage fee for a single message is [`freeze_due_limit`](/foundations/config#param-20-and-21%3A-gas-prices). Otherwise, the contract likely is already frozen and a transaction chain is likely to fail anyway.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the worst case the storage fee for a single message is freeze_due_limit.

It is not clear what is being discussed and what the message has to do with it. Rephrase it.

Verify the hardcoded contract size in tests.
</Aside>

**Approach 2: Cover storage on demand**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The section is generally poorly written. We need to rethink the narrative again and rewrite it.

}
```

This simplifies fee calculation at the start of the operation—you do not need to pre‑calculate storage fees. The `myStorageDue()` function returns the amount needed to bring the balance to zero (or zero if it is already positive).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

myStorageDue() just outputs the storage due, but not the thing described.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Contract dev > Estimate gas usage in TON contracts]

8 participants